repo.or.cz
/
andmenj-acm.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
PC^2 sucks.
[andmenj-acm.git]
/
Mi manual de algoritmos
/
version_actual
/
src
/
misc
/
parser_recursivo_desc.cpp
blob
a2e93ec1623bead7a6260d5a58e66ead76aa3f42
1
//A -> (A)A | Epsilon
2
3
#include <iostream>
4
#include <string>
5
6
using namespace
std
;
7
8
bool
ok
;
9
char
sgte
;
10
int
i
;
11
string s
;
12
13
bool
match
(
char
c
){
14
if
(
sgte
!=
c
){
15
ok
=
false
;
16
}
17
sgte
=
s
[++
i
];
18
}
19
20
void
A
(){
21
if
(
sgte
==
'('
){
22
match
(
'('
);
23
A
();
match
(
')'
);
A
();
24
}
else if
(
sgte
==
'$'
||
sgte
==
')'
){
25
//nada
26
}
else
{
27
ok
=
false
;
28
}
29
}
30
31
int
main
(){
32
while
(
getline
(
cin
,
s
) &&
s
!=
""
){
33
ok
=
true
;
34
s
+=
'$'
;
35
sgte
=
s
[(
i
=
0
)];
36
A
();
37
if
(
i
<
s
.
length
()-
1
)
ok
=
false
;
//No consumi toda la cadena
38
if
(
ok
){
39
cout
<<
"Accepted
\n
"
;
40
}
else
{
41
cout
<<
"Not accepted
\n
"
;
42
}
43
44
}
45
}